//
//  MySearchSingleSongCollectionViewCell.m
//  TTMusic
//
//  Created by yanghuiyan on 16/4/5.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "MySearchSingleSongCollectionViewCell.h"

@implementation MySearchSingleSongCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.singleTableView = [[TTMusicBaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        [self.singleTableView registerClass:[MySearchSingleSongTableViewCell class] forCellReuseIdentifier:@"SingleSong"];
        self.singleTableView.delegate = self;
        self.singleTableView.dataSource = self;
        [self.contentView addSubview:self.singleTableView];
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.singleTableView.frame = CGRectMake(0, 0, SysWidth, self.bounds.size.height);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        MySearchSingleSongTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SingleSong"];
        cell.numLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
    
        SearchSongDataModel *model = _dataSource[indexPath.row];
    
        cell.songModel = model;
    
           return cell;
}

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 1;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (void)setDataSource:(NSMutableArray *)dataSource {
    _dataSource = dataSource;
    [_singleTableView reloadData];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [TTMusicAVPlayer shareTTMusicAVPlayer].local = indexPath.item;
    [[TTMusicAVPlayer shareTTMusicAVPlayer] playWithURL:_songsModel];
}
- (void)setSongsModel:(CPYSONGSModel *)songsModel {
    _songsModel = songsModel;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
